#ifndef __THREAD_POOL__
#define __THREAD_POOL__
#include "taskQueue.h"
#include "nodeStack.h"
#include <syslog.h>

#define NETDISK_LOG_INFO(priority, ip)          \
{           \
    char logMsg[1024];          \
    snprintf(logMsg, sizeof(logMsg), "ip: %s; ", ip);         \
    syslog(priority, "%s", logMsg);            \
}

#define NETDISK_LOG_ERR(priority, msg)          \
{           \
    char logMsg[1024];          \
    snprintf(logMsg, sizeof(logMsg), "File: %s; Line: %d; Func: %s; Msg: %s.", __FILE__, __LINE__, __FUNCTION__, msg);          \
    syslog(priority, "%s", logMsg);         \
}

char absolutePath[256]; // 绝对路径
char relativePath[256]; // 相对路径
typedef struct threadPool_s {
    pthread_t* tidArr;
    int workerNum;
    taskQueue_t taskQueue;
} threadPool_t;

typedef struct train_s {
    int length;
    char data[1000];
} train_t;

int initThreadPool(threadPool_t* pthreadPool, int workerNum);
int tcpInit(char* ip, char* port, int* psockfd);
void* threadFunc(void* arg);
int makeWorker(threadPool_t* pthreadPool);
int epollAdd(int epfd, int fd);
int epollDel(int epfd, int fd);
int transfile(int netfd);
int recvfile(int sockfd);
int recvn(int sockfd, void *buf, int length);
int pushStack(node_t** head, node_t** tail, char* pathname);
int push(node_t** head, node_t** tail, char* pathname);
int pop(node_t** head, node_t** tail);
int createDir(const char* curPath);

#endif
